
var str = "";
$.ajax({
	type: "get",
	url: "../getCardNewsInfo.json",
	data: {
		aid: "d427ee6d-7c41-4a41-bb96-84de0c62a160",
		ps: "10",
		pn: "0",
		date: "2016-4-1 23:59:59"
	},
	dataType: "json",
	beforeSend:function(){
		refresh();
	},
	complete:function(){
		$("#foo").css("display","none");
	},
	success: function(rsp) {
		var myTime = rsp.date;
		var time = transformTime(get(myTime));
		for (var i = 0; i < rsp.list.length; i++) {
			str += '<dl class="news-list"><dt><img src="' + rsp.list[i].imgUrl + '" alt=""/></dt><dd><p class="news-title">' + rsp.list[i].title + '</p><span class="update-time">' + time + '</span></dd></dl>';
		}
		$(".showList").html(str);
		myscroll.refresh();
		tiaozhuao();
	}
});




function tiaozhuao(){ 
	
	/* 点击跳转 */ 
	$(".news-list").click(function(){
		window.location.href="entertainment-newsDetail.html";
	});
	
}

function refresh(){
	var opts = {
		lines: 10, // 个数
		length: 13, // 长度
		width: 8, // 宽度
		radius: 20, // 圆周
		corners: 1, // Corner roundness (0..1)
		rotate: 0, // The rotation offset
		direction: -1, // 1: clockwise, -1: counterclockwise
		color: '#000', // #rgb or #rrggbb or array of colors
		speed: 1, // Rounds per second
		trail: 60, // Afterglow percentage
		shadow: false, // Whether to render a shadow
		hwaccel: false, // Whether to use hardware acceleration
		className: 'spinner', // The CSS class to assign to the spinner
		zIndex: 2e9, // The z-index (defaults to 2000000000)
		top: 'auto', // Top position relative to parent in px
		left: 'auto' // Left position relative to parent in px
	};
	var target = document.getElementById('foo');
	var spinner = new Spinner(opts).spin(target);
}

  

function get(date){
	var myTime = date.split(" "); // 2016-04-04 23:59:59
	var my1 = myTime[0].split("-");
	var my2 = myTime[1].split(":");

	var nowTime = new Date();
	var arr = [nowTime.getFullYear(),(nowTime.getMonth())+1,nowTime.getDate()];
	var arr1 = [nowTime.getHours(),nowTime.getMinutes(),nowTime.getSeconds()];
	
	return fangfa(arr,arr1)-fangfa(my1,my2)

}
function fangfa(time1,time2){
	// 时分秒
	var t1 = time2[0]*3600*1000;
    var t2 = time2[1]*60*1000;
    var t3 = time2[2]*1000;
    var t = t1 + t2 + t3;
	
	// 年月日
	var getTime = t + Date.UTC(time1[0],time1[1],time1[2]); 
	return getTime;
}




// 将毫秒数转化成时间
function transformTime(ms){

	var ss = 1000;
	var mi = ss * 60; // 分钟
	var hh = mi * 60; // 小时
	var dd = hh * 24; // 天

	var day = parseInt(ms / dd);
	var hour = parseInt((ms - day * dd) / hh);
	var minute = parseInt((ms - day * dd - hour * hh) / mi);
	var second = parseInt((ms - day * dd - hour * hh - minute * mi) / ss);
	//var milliSecond = ms - day * dd - hour * hh - minute * mi - second * ss;

	if(day < 1 ){
		if(hour < 1){
			if(minute < 1){
				if(second < 1){
					return "最新"
				}else{
					return second+"秒前"
				}
			}else{
				return minute+"分钟前"
			}
		}else{
			return hour+"小时前"
		}
	}else{
		return day+"天前"
	}
}